{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1616fd13",
   "metadata": {},
   "source": [
    "# 实战\n",
    "\n",
    "4.10章：https://zh-v2.d2l.ai/chapter_multilayer-perceptrons/kaggle-house-price.html#id2  \n",
    "数据集：https://www.kaggle.com/c/house-prices-advanced-regression-techniques"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce5d0091",
   "metadata": {},
   "source": [
    "# 0.下载与缓存数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47e36144",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hashlib\n",
    "import os\n",
    "import tarfile\n",
    "import zipfile\n",
    "import requests\n",
    "\n",
    "#@save\n",
    "DATA_HUB = dict()\n",
    "DATA_URL = 'http://d2l-data.s3-accelerate.amazonaws.com/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04ded5ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "def download(name, cache_dir=os.path.join('..', 'data')):  #@save\n",
    "    \"\"\"下载一个DATA_HUB中的文件，返回本地文件名。\"\"\"\n",
    "    assert name in DATA_HUB, f\"{name} 不存在于 {DATA_HUB}.\"\n",
    "    url, sha1_hash = DATA_HUB[name]\n",
    "    os.makedirs(cache_dir, exist_ok=True)\n",
    "    fname = os.path.join(cache_dir, url.split('/')[-1])\n",
    "    if os.path.exists(fname):\n",
    "        sha1 = hashlib.sha1()\n",
    "        with open(fname, 'rb') as f:\n",
    "            while True:\n",
    "                data = f.read(1048576)\n",
    "                if not data:\n",
    "                    break\n",
    "                sha1.update(data)\n",
    "        if sha1.hexdigest() == sha1_hash:\n",
    "            return fname  # Hit cache\n",
    "    print(f'正在从{url}下载{fname}...')\n",
    "    r = requests.get(url, stream=True, verify=True)\n",
    "    with open(fname, 'wb') as f:\n",
    "        f.write(r.content)\n",
    "    return fname"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dac2059",
   "metadata": {},
   "outputs": [],
   "source": [
    "def download_extract(name, folder=None):  #@save\n",
    "    \"\"\"下载并解压zip/tar文件。\"\"\"\n",
    "    fname = download(name)\n",
    "    base_dir = os.path.dirname(fname)\n",
    "    data_dir, ext = os.path.splitext(fname)\n",
    "    if ext == '.zip':\n",
    "        fp = zipfile.ZipFile(fname, 'r')\n",
    "    elif ext in ('.tar', '.gz'):\n",
    "        fp = tarfile.open(fname, 'r')\n",
    "    else:\n",
    "        assert False, '只有zip/tar文件可以被解压缩。'\n",
    "    fp.extractall(base_dir)\n",
    "    return os.path.join(base_dir, folder) if folder else data_dir\n",
    "\n",
    "def download_all():  #@save\n",
    "    \"\"\"下载DATA_HUB中的所有文件。\"\"\"\n",
    "    for name in DATA_HUB:\n",
    "        download(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec0f8ab1",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_HUB['kaggle_house_train'] = (  #@save\n",
    "    DATA_URL + 'kaggle_house_pred_train.csv',\n",
    "    '585e9cc93e70b39160e7921475f9bcd7d31219ce')\n",
    "\n",
    "DATA_HUB['kaggle_house_test'] = (  #@save\n",
    "    DATA_URL + 'kaggle_house_pred_test.csv',\n",
    "    'fa19780a7b011d9b009e8bff8e99922a8ee2eb90')\n",
    "\n",
    "download('kaggle_house_train')\n",
    "download('kaggle_house_test')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bc44de9",
   "metadata": {},
   "source": [
    "# 1.读取csv\n",
    "```\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "```\n",
    "\n",
    ">**pandas读取csv文件**\n",
    ">>`数据集 = pd.read_csv('csv路径')`\n",
    "\n",
    ">**查看csv数据格式**\n",
    ">>输出结果：(不包含标题的样本数, csv列数)\n",
    ">>`print(数据集.shape)` \n",
    "\n",
    ">**查看csv数据**\n",
    ">>数据集.iloc[行, [列1, 列2]]\n",
    "\n",
    ">**数据拼接**\n",
    ">>pd.concat([数据集.iloc[行, 列], 数据集.iloc[行, 列]], axis=0)\n",
    "\n",
    ">**获取某特征全部值**\n",
    ">>数据集[\"特征列名\"].values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "05881bb3",
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2b5fb2f",
   "metadata": {},
   "source": [
    "### （1）pandas读取csv文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "66065572",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data = pd.read_csv('../data/kaggle_house_pred_train.csv')\n",
    "test_data = pd.read_csv('../data/kaggle_house_pred_test.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "489fa31a",
   "metadata": {},
   "source": [
    "### （2）查看CSV样本格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d50bf899",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1460, 81)\n",
      "(1459, 80)\n"
     ]
    }
   ],
   "source": [
    "print(train_data.shape) #1460个样本，一个样本有81列（80个特征+1个标签）\n",
    "print(test_data.shape) #1459个样本，一个样本有80列（80个特征）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c58a31ce",
   "metadata": {},
   "source": [
    "### （3）查看csv数据内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2ff10479",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Id  MSSubClass MSZoning  LotFrontage SaleType SaleCondition  SalePrice\n",
      "0   1          60       RL         65.0       WD        Normal     208500\n",
      "1   2          20       RL         80.0       WD        Normal     181500\n",
      "2   3          60       RL         68.0       WD        Normal     223500\n",
      "3   4          70       RL         60.0       WD       Abnorml     140000\n"
     ]
    }
   ],
   "source": [
    "# 看前四个和最后两个特征，以及相应标签（房价）\n",
    "print(train_data.iloc[0:4, [0, 1, 2, 3, -3, -2, -1]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b57cb3a2",
   "metadata": {},
   "source": [
    "### （4）数据拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0adb2ae6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   MSSubClass MSZoning  LotFrontage  LotArea  YrSold SaleType SaleCondition\n",
      "0          60       RL         65.0     8450    2008       WD        Normal\n",
      "1          20       RL         80.0     9600    2007       WD        Normal\n",
      "2          60       RL         68.0    11250    2008       WD        Normal\n",
      "3          70       RL         60.0     9550    2006       WD       Abnorml\n"
     ]
    }
   ],
   "source": [
    "# 去除id，将训练集与测试集的特征连接起来，便于统一处理\n",
    "all_features = pd.concat([train_data.iloc[:, 1:-1], test_data.iloc[:, 1:]], axis=0)  # 全特征值\n",
    "\n",
    "print(all_features.iloc[0:4, [0, 1, 2, 3, -3, -2, -1]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92ad11f6",
   "metadata": {},
   "source": [
    "---\n",
    "# 2.数据预处理\n",
    "```python\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import torch\n",
    "```\n",
    ">**查看特征的数据类型**\n",
    ">>数据集.dtypes\n",
    "\n",
    ">**选取特征**  \n",
    ">>得到数值特征的列名: `标签名列表 = 数据集.dtypes[数据集.dtypes != 'object'].index `  \n",
    ">>得到非数值特征的列名:`标签名列表 = 数据集.dtypes[数据集.dtypes == 'object'].index `\n",
    "\n",
    "\n",
    ">**# 数值型数据处理 （数据集.dtypes != 'object'）**\n",
    ">>标准化\n",
    ">>>`数据集[标签名列表] = 数据集[标签名列表].apply(lambda x: (x - x.mean()) / (x.std()))`  \n",
    "\n",
    ">>空值填充\n",
    ">>>`数据集[标签名列表] = 数据集[标签名列表].fillna(处理方法)`  \n",
    ">>>处理方法=0：将空值用0填充  \n",
    ">>>处理方法=数据集.mean()：将空值用平均值填充\n",
    "\n",
    "\n",
    ">**# 非数值型数据处理**\n",
    ">>将文本数据变为数值（one-hot编码）\n",
    ">>>`数据集变量 = pd.get_dummies(数据集变量, dummy_na=是否将缺失值分类True/False)`\n",
    "\n",
    "\n",
    ">**数据转换**\n",
    ">>将pandas转换为tensor\n",
    ">>>取出多样本全部特征数据：`torch.tensor(数据集[行范围:行范围].values,dtype=torch.float)`  \n",
    ">>>取出多样本某特征数据(结果为一行)：`torch.tensor(数据集[行范围][\"列名\"].values,dtype=torch.float)`  \n",
    ">>>取出多样本某特征数据(结果为一列)：`torch.tensor(数据集[行范围][[\"列名\"]].values,dtype=torch.float)`  \n",
    ">>>取出多样本多特征数据：`torch.tensor(数据集[行范围][[\"列名\",\"列名\"]].values,dtype=torch.float)`\n",
    "\n",
    ">tensor数据格式转换\n",
    ">>`tensor数据集.view(行数,列数)`  \n",
    ">>说明：若不知道结果的行数，仅知道列数，可以写作.view(-1,列数)，用-1代表未知"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3663f4cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import torch"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d69fe4c7",
   "metadata": {},
   "source": [
    "### （1）查看特征的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7048da56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MSSubClass         int64\n",
       "MSZoning          object\n",
       "LotFrontage      float64\n",
       "LotArea            int64\n",
       "Street            object\n",
       "                  ...   \n",
       "MiscVal            int64\n",
       "MoSold             int64\n",
       "YrSold             int64\n",
       "SaleType          object\n",
       "SaleCondition     object\n",
       "Length: 79, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_features.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c7df4e0",
   "metadata": {},
   "source": [
    "### （2）选取特征（得到特征名）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b0721e4b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数值特征列名： Index(['MSSubClass', 'LotFrontage', 'LotArea', 'OverallQual', 'OverallCond',\n",
      "       'YearBuilt', 'YearRemodAdd', 'MasVnrArea', 'BsmtFinSF1', 'BsmtFinSF2',\n",
      "       'BsmtUnfSF', 'TotalBsmtSF', '1stFlrSF', '2ndFlrSF', 'LowQualFinSF',\n",
      "       'GrLivArea', 'BsmtFullBath', 'BsmtHalfBath', 'FullBath', 'HalfBath',\n",
      "       'BedroomAbvGr', 'KitchenAbvGr', 'TotRmsAbvGrd', 'Fireplaces',\n",
      "       'GarageYrBlt', 'GarageCars', 'GarageArea', 'WoodDeckSF', 'OpenPorchSF',\n",
      "       'EnclosedPorch', '3SsnPorch', 'ScreenPorch', 'PoolArea', 'MiscVal',\n",
      "       'MoSold', 'YrSold'],\n",
      "      dtype='object')\n",
      "非数值特征列名： Index(['MSZoning', 'Street', 'Alley', 'LotShape', 'LandContour', 'Utilities',\n",
      "       'LotConfig', 'LandSlope', 'Neighborhood', 'Condition1', 'Condition2',\n",
      "       'BldgType', 'HouseStyle', 'RoofStyle', 'RoofMatl', 'Exterior1st',\n",
      "       'Exterior2nd', 'MasVnrType', 'ExterQual', 'ExterCond', 'Foundation',\n",
      "       'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2',\n",
      "       'Heating', 'HeatingQC', 'CentralAir', 'Electrical', 'KitchenQual',\n",
      "       'Functional', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageQual',\n",
      "       'GarageCond', 'PavedDrive', 'PoolQC', 'Fence', 'MiscFeature',\n",
      "       'SaleType', 'SaleCondition'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# 取出所有的数值型特征名称（列标题）\n",
    "numeric_features = all_features.dtypes[all_features.dtypes != 'object'].index\n",
    "print('数值特征列名：', numeric_features)\n",
    "\n",
    "# 取出所有的非数值型特征名称（列标题）\n",
    "object_features = all_features.dtypes[all_features.dtypes == 'object'].index\n",
    "print('非数值特征列名：', object_features)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6b4d7cd",
   "metadata": {},
   "source": [
    "### （3.1）数值数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4089d0c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将数值型特征进行 z-score 标准化\n",
    "all_features[numeric_features] = all_features[numeric_features].apply(\n",
    "    lambda x: (x - x.mean()) / (x.std()))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b7af346a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 在标准化数据之后，所有数据都意味着消失，因此我们可以将缺失值设置为0\n",
    "all_features[numeric_features] = all_features[numeric_features].fillna(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7328e614",
   "metadata": {},
   "source": [
    "### （3.2）非数值数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "36ace5a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2919, 331)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 非数值数据预处理\n",
    "\n",
    "# 将缺省值NA视为有效特征值\n",
    "all_features = pd.get_dummies(all_features, dummy_na=True)\n",
    "\n",
    "all_features.shape # 2919个样本，每个样本331个特征"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a57154ae",
   "metadata": {},
   "source": [
    "### （4）数据格式转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "112edeb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 0.0673, -0.1844, -0.2178,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735,  0.4581, -0.0720,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [ 0.0673, -0.0559,  0.1372,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        ...,\n",
      "        [ 0.3025, -0.1416, -0.1428,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735, -0.0559, -0.0572,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735,  0.2439, -0.0293,  ...,  1.0000,  0.0000,  0.0000]])\n"
     ]
    }
   ],
   "source": [
    "# 将数据转换为tensor格式\n",
    "n_train = train_data.shape[0]  # 训练集个数\n",
    "\n",
    "# 训练样本与测试样本特征转换为tensor\n",
    "train_features = torch.tensor(all_features[:n_train].values,dtype=torch.float)\n",
    "test_features = torch.tensor(all_features[n_train:].values,dtype=torch.float)\n",
    "\n",
    "print(train_features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cd01eafb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([208500., 181500., 223500.,  ..., 266500., 142125., 147500.])\n",
      "tensor([[208500.],\n",
      "        [181500.],\n",
      "        [223500.],\n",
      "        ...,\n",
      "        [266500.],\n",
      "        [142125.],\n",
      "        [147500.]])\n"
     ]
    }
   ],
   "source": [
    "# 训练样本标签转换为tensor\n",
    "train_labels = torch.tensor(train_data[\"SalePrice\"].values,dtype=torch.float)\n",
    "print(train_labels)\n",
    "\n",
    "# 训练标签数据变为1列\n",
    "train_labels = train_labels.view(-1,1)\n",
    "print(train_labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf355f11",
   "metadata": {},
   "source": [
    "---\n",
    "# 3.搭建神经网络模型（调包）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2b5859a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn, optim\n",
    "import torch.nn.functional as F"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19b6e9a1",
   "metadata": {},
   "source": [
    "### 创建数据集与加载数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c53cc024",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(tensor([[ 0.0673, -0.1844, -0.2178,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735,  0.4581, -0.0720,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [ 0.0673, -0.0559,  0.1372,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        ...,\n",
      "        [ 0.3025, -0.1416, -0.1428,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735, -0.0559, -0.0572,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735,  0.2439, -0.0293,  ...,  1.0000,  0.0000,  0.0000]]), tensor([[208500.],\n",
      "        [181500.],\n",
      "        [223500.],\n",
      "        ...,\n",
      "        [266500.],\n",
      "        [142125.],\n",
      "        [147500.]]), tensor([[-0.1679, -0.3986,  0.1573,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [ 0.0673,  0.0000,  0.8230,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [-0.8735,  0.4581, -0.0720,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        ...,\n",
      "        [-0.8735,  1.2291,  0.3215,  ...,  0.0000,  1.0000,  0.0000],\n",
      "        [ 0.7729,  0.5009,  0.2121,  ...,  1.0000,  0.0000,  0.0000],\n",
      "        [ 0.4201,  0.2439,  0.4225,  ...,  1.0000,  0.0000,  0.0000]]), tensor([[131000.],\n",
      "        [235000.],\n",
      "        [167000.],\n",
      "        [142500.],\n",
      "        [152000.],\n",
      "        [239000.],\n",
      "        [175000.],\n",
      "        [158500.],\n",
      "        [157000.],\n",
      "        [267000.],\n",
      "        [205000.],\n",
      "        [149900.],\n",
      "        [295000.],\n",
      "        [305900.],\n",
      "        [225000.],\n",
      "        [ 89500.],\n",
      "        [ 82500.],\n",
      "        [360000.],\n",
      "        [165600.],\n",
      "        [132000.],\n",
      "        [119900.],\n",
      "        [375000.],\n",
      "        [178000.],\n",
      "        [188500.],\n",
      "        [260000.],\n",
      "        [270000.],\n",
      "        [260000.],\n",
      "        [187500.],\n",
      "        [342643.],\n",
      "        [354000.],\n",
      "        [301000.],\n",
      "        [126175.],\n",
      "        [242000.],\n",
      "        [ 87000.],\n",
      "        [324000.],\n",
      "        [145250.],\n",
      "        [214500.],\n",
      "        [ 78000.],\n",
      "        [119000.],\n",
      "        [139000.],\n",
      "        [284000.],\n",
      "        [207000.],\n",
      "        [192000.],\n",
      "        [228950.],\n",
      "        [377426.],\n",
      "        [214000.],\n",
      "        [202500.],\n",
      "        [155000.],\n",
      "        [202900.],\n",
      "        [ 82000.],\n",
      "        [ 87500.],\n",
      "        [266000.],\n",
      "        [ 85000.],\n",
      "        [140200.],\n",
      "        [151500.],\n",
      "        [157500.],\n",
      "        [154000.],\n",
      "        [437154.],\n",
      "        [318061.],\n",
      "        [190000.],\n",
      "        [ 95000.],\n",
      "        [105900.],\n",
      "        [140000.],\n",
      "        [177500.],\n",
      "        [173000.],\n",
      "        [134000.],\n",
      "        [130000.],\n",
      "        [280000.],\n",
      "        [156000.],\n",
      "        [145000.],\n",
      "        [198500.],\n",
      "        [118000.],\n",
      "        [190000.],\n",
      "        [147000.],\n",
      "        [159000.],\n",
      "        [165000.],\n",
      "        [132000.],\n",
      "        [162000.],\n",
      "        [172400.],\n",
      "        [134432.],\n",
      "        [125000.],\n",
      "        [123000.],\n",
      "        [219500.],\n",
      "        [ 61000.],\n",
      "        [148000.],\n",
      "        [340000.],\n",
      "        [394432.],\n",
      "        [179000.],\n",
      "        [127000.],\n",
      "        [187750.],\n",
      "        [213500.],\n",
      "        [ 76000.],\n",
      "        [240000.],\n",
      "        [192000.],\n",
      "        [ 81000.],\n",
      "        [125000.],\n",
      "        [191000.],\n",
      "        [426000.],\n",
      "        [119000.],\n",
      "        [215000.],\n",
      "        [106500.],\n",
      "        [100000.],\n",
      "        [109000.],\n",
      "        [129000.],\n",
      "        [123000.],\n",
      "        [169500.],\n",
      "        [ 67000.],\n",
      "        [241000.],\n",
      "        [245500.],\n",
      "        [164990.],\n",
      "        [108000.],\n",
      "        [258000.],\n",
      "        [168000.],\n",
      "        [150000.],\n",
      "        [115000.],\n",
      "        [177000.],\n",
      "        [280000.],\n",
      "        [339750.],\n",
      "        [ 60000.],\n",
      "        [145000.],\n",
      "        [222000.],\n",
      "        [115000.],\n",
      "        [228000.],\n",
      "        [181134.],\n",
      "        [149500.],\n",
      "        [239000.],\n",
      "        [126000.],\n",
      "        [142000.],\n",
      "        [206300.],\n",
      "        [215000.],\n",
      "        [113000.],\n",
      "        [315000.],\n",
      "        [139000.],\n",
      "        [135000.],\n",
      "        [275000.],\n",
      "        [109008.],\n",
      "        [195400.],\n",
      "        [175000.],\n",
      "        [ 85400.],\n",
      "        [ 79900.],\n",
      "        [122500.],\n",
      "        [181000.],\n",
      "        [ 81000.],\n",
      "        [212000.],\n",
      "        [116000.],\n",
      "        [119000.],\n",
      "        [ 90350.],\n",
      "        [110000.],\n",
      "        [555000.],\n",
      "        [118000.],\n",
      "        [162900.],\n",
      "        [172500.],\n",
      "        [210000.],\n",
      "        [127500.],\n",
      "        [190000.],\n",
      "        [199900.],\n",
      "        [119500.],\n",
      "        [120000.],\n",
      "        [110000.],\n",
      "        [280000.],\n",
      "        [204000.],\n",
      "        [210000.],\n",
      "        [188000.],\n",
      "        [175500.],\n",
      "        [ 98000.],\n",
      "        [256000.],\n",
      "        [161000.],\n",
      "        [110000.],\n",
      "        [263435.],\n",
      "        [155000.],\n",
      "        [ 62383.],\n",
      "        [188700.],\n",
      "        [124000.],\n",
      "        [178740.],\n",
      "        [167000.],\n",
      "        [146500.],\n",
      "        [250000.],\n",
      "        [187000.],\n",
      "        [212000.],\n",
      "        [190000.],\n",
      "        [148000.],\n",
      "        [440000.],\n",
      "        [251000.],\n",
      "        [132500.],\n",
      "        [208900.],\n",
      "        [380000.],\n",
      "        [297000.],\n",
      "        [ 89471.],\n",
      "        [326000.],\n",
      "        [374000.],\n",
      "        [155000.],\n",
      "        [164000.],\n",
      "        [132500.],\n",
      "        [147000.],\n",
      "        [156000.],\n",
      "        [175000.],\n",
      "        [160000.],\n",
      "        [ 86000.],\n",
      "        [115000.],\n",
      "        [133000.],\n",
      "        [172785.],\n",
      "        [155000.],\n",
      "        [ 91300.],\n",
      "        [ 34900.],\n",
      "        [430000.],\n",
      "        [184000.],\n",
      "        [130000.],\n",
      "        [120000.],\n",
      "        [113000.],\n",
      "        [226700.],\n",
      "        [140000.],\n",
      "        [289000.],\n",
      "        [147000.],\n",
      "        [124500.],\n",
      "        [215000.],\n",
      "        [208300.],\n",
      "        [161000.],\n",
      "        [124500.],\n",
      "        [164900.],\n",
      "        [202665.],\n",
      "        [129900.],\n",
      "        [134000.],\n",
      "        [ 96500.],\n",
      "        [402861.],\n",
      "        [158000.],\n",
      "        [265000.],\n",
      "        [211000.],\n",
      "        [234000.],\n",
      "        [106250.],\n",
      "        [150000.],\n",
      "        [159000.],\n",
      "        [184750.],\n",
      "        [315750.],\n",
      "        [176000.],\n",
      "        [132000.],\n",
      "        [446261.],\n",
      "        [ 86000.],\n",
      "        [200624.],\n",
      "        [175000.],\n",
      "        [128000.],\n",
      "        [107500.],\n",
      "        [ 39300.],\n",
      "        [178000.],\n",
      "        [107500.],\n",
      "        [188000.],\n",
      "        [111250.],\n",
      "        [158000.],\n",
      "        [272000.],\n",
      "        [315000.],\n",
      "        [248000.],\n",
      "        [213250.],\n",
      "        [133000.],\n",
      "        [179665.],\n",
      "        [229000.],\n",
      "        [210000.],\n",
      "        [129500.],\n",
      "        [125000.],\n",
      "        [263000.],\n",
      "        [140000.],\n",
      "        [112500.],\n",
      "        [255500.],\n",
      "        [108000.],\n",
      "        [284000.],\n",
      "        [113000.],\n",
      "        [141000.],\n",
      "        [108000.],\n",
      "        [175000.],\n",
      "        [234000.],\n",
      "        [121500.],\n",
      "        [170000.],\n",
      "        [108000.],\n",
      "        [185000.],\n",
      "        [268000.],\n",
      "        [128000.],\n",
      "        [325000.],\n",
      "        [214000.],\n",
      "        [316600.],\n",
      "        [135960.],\n",
      "        [142600.],\n",
      "        [120000.],\n",
      "        [224500.],\n",
      "        [170000.],\n",
      "        [139000.],\n",
      "        [118500.],\n",
      "        [145000.],\n",
      "        [164500.],\n",
      "        [146000.],\n",
      "        [131500.],\n",
      "        [181900.],\n",
      "        [253293.],\n",
      "        [118500.],\n",
      "        [325000.]]))\n"
     ]
    }
   ],
   "source": [
    "def get_k_fold_data(k, i, X, y):\n",
    "    assert k > 1\n",
    "    fold_size = X.shape[0] // k\n",
    "    X_train, y_train = None, None\n",
    "    for j in range(k):\n",
    "        idx = slice(j * fold_size, (j + 1) * fold_size)\n",
    "        X_part, y_part = X[idx, :], y[idx]\n",
    "        if j == i:\n",
    "            X_valid, y_valid = X_part, y_part\n",
    "        elif X_train is None:\n",
    "            X_train, y_train = X_part, y_part\n",
    "        else:\n",
    "            X_train = torch.cat([X_train, X_part], 0)\n",
    "            y_train = torch.cat([y_train, y_part], 0)\n",
    "    return X_train, y_train, X_valid, y_valid\n",
    "\n",
    "test = get_k_fold_data(5, 1, train_features, train_labels)\n",
    "print(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f5f7cb58",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torch.utils.data import Dataset, TensorDataset, DataLoader\n",
    "\n",
    "train_dataset = TensorDataset(train_features, train_labels)\n",
    "\n",
    "train_loader = DataLoader(dataset=train_dataset, batch_size=64, shuffle=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cb01b93a",
   "metadata": {},
   "source": [
    "### （1）定义神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e9fb93fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "class Net(nn.Module):\n",
    "    def __init__(self, input_feature):\n",
    "        super().__init__()\n",
    "        self.layer1 = nn.Sequential(\n",
    "            nn.Linear(input_feature, 600),\n",
    "            nn.ReLU(),\n",
    "        )\n",
    "        self.layer2 = nn.Sequential(\n",
    "            nn.Linear(600, 1200),\n",
    "            nn.ReLU(),\n",
    "        )\n",
    "        self.layer3 = nn.Sequential(\n",
    "            nn.Linear(1200, 1),\n",
    "            nn.ReLU(),\n",
    "        )\n",
    "        \n",
    "    def forward(self, x):   \n",
    "        x = self.layer1(x)\n",
    "        x = self.layer2(x)\n",
    "        x = self.layer3(x)\n",
    "        return x\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76d098a3",
   "metadata": {},
   "source": [
    "### （2）实例化神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "90c8fa1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from torchkeras import summary,Model\n",
    "\n",
    "# 实例化模型\n",
    "model = Model(Net(331))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8be341b",
   "metadata": {},
   "source": [
    "### （3）编译神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f799aa17",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "def accuracy(y_pred,y_true):\n",
    "    y_pred_cls = torch.argmax(nn.Softmax(dim=1)(y_pred),dim=1).data\n",
    "    return accuracy_score(y_true.numpy(),y_pred_cls.numpy())\n",
    "\n",
    "model.compile(loss_func = nn.MSELoss(),\n",
    "             optimizer= torch.optim.Adam(model.parameters(), lr=5, weight_decay=0),\n",
    "             metrics_dict={\"accuracy\":accuracy})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09898967",
   "metadata": {},
   "source": [
    "### （4）训练神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a7a5692b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Start Training ...\n",
      "\n",
      "================================================================================2021-10-23 10:19:47\n",
      "\n",
      " +-------+--------------------+----------+\n",
      "| epoch |        loss        | accuracy |\n",
      "+-------+--------------------+----------+\n",
      "|   1   | 2387710122352729.0 |   0.0    |\n",
      "+-------+--------------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:47\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   2   | 39011118658.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:47\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   3   | 39002049491.478 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:48\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   4   | 39031755820.522 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:48\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   5   | 39101429849.043 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:48\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   6   | 38946509690.435 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:48\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   7   | 39018644168.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:48\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   8   | 38986606057.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:49\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   9   | 39007887894.261 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:49\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   10  | 38963902196.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:49\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   11  | 39091607195.826 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:49\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   12  | 39048735343.304 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:50\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   13  | 38982730796.522 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:50\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   14  | 38991379411.478 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:50\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   15  | 38929414678.261 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:50\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   16  | 38962132101.565 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:51\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   17  | 38992841416.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:51\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   18  | 39130432111.304 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:51\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   19  | 39002141206.261 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:51\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   20  | 39098788552.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:52\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   21  | 39066151268.174 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:52\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   22  | 39038767905.391 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:52\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   23  | 39066504681.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:52\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   24  | 39047654889.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:53\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   25  | 39071002713.043 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:53\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   26  | 39011041992.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:53\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   27  | 39066650178.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:53\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   28  | 39013385705.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:54\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   29  | 38980546292.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:54\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   30  | 38981367540.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:54\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   31  | 39023275408.696 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:54\n",
      "\n",
      " +-------+---------------+----------+\n",
      "| epoch |      loss     | accuracy |\n",
      "+-------+---------------+----------+\n",
      "|   32  | 39139801088.0 |   0.0    |\n",
      "+-------+---------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:55\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   33  | 38977593878.261 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:55\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   34  | 38996337085.217 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:55\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   35  | 39002927816.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:55\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   36  | 39020916379.826 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:55\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   37  | 39013520428.522 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:56\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   38  | 39138424742.957 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:56\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   39  | 39000869220.174 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:56\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   40  | 38982037949.217 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:56\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   41  | 39052783794.087 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:57\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   42  | 38983458637.913 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:57\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   43  | 39045578395.826 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:57\n",
      "\n",
      " +-------+---------------+----------+\n",
      "| epoch |      loss     | accuracy |\n",
      "+-------+---------------+----------+\n",
      "|   44  | 39059638272.0 |   0.0    |\n",
      "+-------+---------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:57\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   45  | 39050898387.478 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:58\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   46  | 39075307252.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:58\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   47  | 39030084741.565 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:58\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   48  | 38985930217.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:58\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   49  | 39000392926.609 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:59\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   50  | 38981088745.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:59\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   51  | 39101440356.174 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:19:59\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   52  | 39017936450.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:00\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   53  | 39034632013.913 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:00\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   54  | 39113926032.696 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:00\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   55  | 38970102027.13 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:00\n",
      "\n",
      " +-------+---------------+----------+\n",
      "| epoch |      loss     | accuracy |\n",
      "+-------+---------------+----------+\n",
      "|   56  | 38982438912.0 |   0.0    |\n",
      "+-------+---------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:01\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   57  | 38971283990.261 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:01\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   58  | 39128588377.043 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:01\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   59  | 39059588674.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:02\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   60  | 38999715305.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:02\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   61  | 39070291522.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:02\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   62  | 39048169382.957 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:02\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   63  | 38986692786.087 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:03\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   64  | 39009884783.304 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:03\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   65  | 39034352595.478 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:03\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   66  | 38958728058.435 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:03\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   67  | 39102916875.13 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:04\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   68  | 38956932229.565 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:04\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   69  | 38960535284.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:04\n",
      "\n",
      " +-------+---------------+----------+\n",
      "| epoch |      loss     | accuracy |\n",
      "+-------+---------------+----------+\n",
      "|   70  | 39014529024.0 |   0.0    |\n",
      "+-------+---------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:05\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   71  | 39028188293.565 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:05\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   72  | 38982819394.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:05\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   73  | 39044135179.13 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:05\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   74  | 39014272222.609 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:06\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   75  | 39138588582.957 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:06\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   76  | 39100963706.435 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:06\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   77  | 39020173757.217 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:06\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   78  | 39101957787.826 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:07\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   79  | 39032934221.913 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:07\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   80  | 38951443589.565 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:07\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   81  | 39019310658.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:08\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   82  | 39037091305.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:08\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   83  | 38963873881.043 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:08\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   84  | 39025423048.348 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:08\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   85  | 39241752130.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:09\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   86  | 39015424178.087 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:09\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   87  | 38961977700.174 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:09\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   88  | 39124137805.913 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:10\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   89  | 38992854594.783 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:10\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   90  | 38993611019.13 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:10\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   91  | 39057177644.522 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:10\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   92  | 39062765033.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:11\n",
      "\n",
      " +-------+----------------+----------+\n",
      "| epoch |      loss      | accuracy |\n",
      "+-------+----------------+----------+\n",
      "|   93  | 39031510772.87 |   0.0    |\n",
      "+-------+----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:11\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   94  | 38973070736.696 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:11\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   95  | 39112472219.826 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:12\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   96  | 38983977138.087 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:12\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   97  | 39105498957.913 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:12\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   98  | 39016962671.304 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:12\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|   99  | 39022772313.043 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:13\n",
      "\n",
      " +-------+-----------------+----------+\n",
      "| epoch |       loss      | accuracy |\n",
      "+-------+-----------------+----------+\n",
      "|  100  | 39152733673.739 |   0.0    |\n",
      "+-------+-----------------+----------+\n",
      "\n",
      "================================================================================2021-10-23 10:20:13\n",
      "Finished Training...\n"
     ]
    }
   ],
   "source": [
    "dfhistory = model.fit(100,train_loader, log_step_freq=100) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4924d5bc",
   "metadata": {},
   "source": [
    "# 3.搭建神经网络模型（自建）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb15b3cc",
   "metadata": {},
   "source": [
    "### （1）定义神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "71f5d116",
   "metadata": {},
   "outputs": [],
   "source": [
    "loss = nn.MSELoss()\n",
    "in_features = train_features.shape[1]\n",
    "\n",
    "# 定义神经网络\n",
    "def get_net():\n",
    "    net = nn.Sequential(nn.Linear(in_features,1))\n",
    "    return net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4deda3fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "def log_rmse(net, features, labels):\n",
    "    # 为了在取对数时进一步稳定该值，将小于1的值设置为1\n",
    "    clipped_preds = torch.clamp(net(features), 1, float('inf'))\n",
    "    rmse = torch.sqrt(loss(torch.log(clipped_preds),\n",
    "                           torch.log(labels)))\n",
    "    return rmse.item()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a295acd",
   "metadata": {},
   "source": [
    "### （2）训练神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "71496255",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练(网络，训练特征，训练标签，测试特征，测试标签，训练次数，训练率，权值，一次训练数据数)\n",
    "def train(net, train_features, train_labels, test_features, test_labels,\n",
    "          num_epochs, learning_rate, weight_decay, batch_size):\n",
    "    train_ls, test_ls = [], []\n",
    "    \n",
    "    # 加载数据集（等价于TensorDataset 和 DataLoader）\n",
    "    train_iter = d2l.load_array((train_features, train_labels), batch_size)\n",
    "    \n",
    "    # 这里使用的是Adam优化算法\n",
    "    optimizer = torch.optim.Adam(net.parameters(),\n",
    "                                 lr = learning_rate,\n",
    "                                 weight_decay = weight_decay)\n",
    "    \n",
    "    # 训练\n",
    "    for epoch in range(num_epochs):\n",
    "        for X, y in train_iter:\n",
    "            optimizer.zero_grad()\n",
    "            l = loss(net(X), y)\n",
    "            l.backward()\n",
    "            optimizer.step()\n",
    "        train_ls.append(log_rmse(net, train_features, train_labels))\n",
    "        if test_labels is not None:\n",
    "            test_ls.append(log_rmse(net, test_features, test_labels))\n",
    "    return train_ls, test_ls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71ee3159",
   "metadata": {},
   "source": [
    "### k折交叉验证得到数据集（创建数据集）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "87dc7bfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_k_fold_data(k, i, X, y):\n",
    "    assert k > 1\n",
    "    fold_size = X.shape[0] // k\n",
    "    X_train, y_train = None, None\n",
    "    for j in range(k):\n",
    "        idx = slice(j * fold_size, (j + 1) * fold_size)\n",
    "        X_part, y_part = X[idx, :], y[idx]\n",
    "        if j == i:\n",
    "            X_valid, y_valid = X_part, y_part\n",
    "        elif X_train is None:\n",
    "            X_train, y_train = X_part, y_part\n",
    "        else:\n",
    "            X_train = torch.cat([X_train, X_part], 0)\n",
    "            y_train = torch.cat([y_train, y_part], 0)\n",
    "    return X_train, y_train, X_valid, y_valid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "fa908738",
   "metadata": {},
   "outputs": [],
   "source": [
    "def k_fold(k, X_train, y_train, num_epochs, learning_rate, weight_decay,\n",
    "           batch_size):\n",
    "    train_l_sum, valid_l_sum = 0, 0\n",
    "    \n",
    "    for i in range(k):\n",
    "        # k折交叉验证数据（自定义函数）\n",
    "        data = get_k_fold_data(k, i, X_train, y_train)\n",
    "        # 神经网络（自定义函数）\n",
    "        net = get_net()\n",
    "        \n",
    "        # 训练（自定义函数）\n",
    "        train_ls, valid_ls = train(net, *data, num_epochs, learning_rate,\n",
    "                                   weight_decay, batch_size)\n",
    "        train_l_sum += train_ls[-1]\n",
    "        valid_l_sum += valid_ls[-1]\n",
    "        \n",
    "        if i == 0:\n",
    "            d2l.plot(list(range(1, num_epochs + 1)), [train_ls, valid_ls],\n",
    "                     xlabel='epoch', ylabel='rmse', xlim=[1, num_epochs],\n",
    "                     legend=['train', 'valid'], yscale='log')\n",
    "        print(f'fold {i + 1}, train log rmse {float(train_ls[-1]):f}, '\n",
    "              f'valid log rmse {float(valid_ls[-1]):f}')\n",
    "    return train_l_sum / k, valid_l_sum / k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ce0b97e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fold 1, train log rmse 0.170468, valid log rmse 0.157072\n",
      "fold 2, train log rmse 0.162280, valid log rmse 0.189854\n",
      "fold 3, train log rmse 0.163850, valid log rmse 0.168387\n",
      "fold 4, train log rmse 0.168503, valid log rmse 0.154637\n",
      "fold 5, train log rmse 0.164116, valid log rmse 0.183393\n",
      "5-折验证: 平均训练log rmse: 0.165843, 平均验证log rmse: 0.170668\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Created with matplotlib (https://matplotlib.org/) -->\r\n",
       "<svg height=\"180.65625pt\" version=\"1.1\" viewBox=\"0 0 257.521875 180.65625\" width=\"257.521875pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       " <metadata>\r\n",
       "  <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\r\n",
       "   <cc:Work>\r\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\r\n",
       "    <dc:date>2021-10-23T10:20:38.723045</dc:date>\r\n",
       "    <dc:format>image/svg+xml</dc:format>\r\n",
       "    <dc:creator>\r\n",
       "     <cc:Agent>\r\n",
       "      <dc:title>Matplotlib v3.3.4, https://matplotlib.org/</dc:title>\r\n",
       "     </cc:Agent>\r\n",
       "    </dc:creator>\r\n",
       "   </cc:Work>\r\n",
       "  </rdf:RDF>\r\n",
       " </metadata>\r\n",
       " <defs>\r\n",
       "  <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\r\n",
       " </defs>\r\n",
       " <g id=\"figure_1\">\r\n",
       "  <g id=\"patch_1\">\r\n",
       "   <path d=\"M 0 180.65625 \r\n",
       "L 257.521875 180.65625 \r\n",
       "L 257.521875 0 \r\n",
       "L 0 0 \r\n",
       "z\r\n",
       "\" style=\"fill:none;\"/>\r\n",
       "  </g>\r\n",
       "  <g id=\"axes_1\">\r\n",
       "   <g id=\"patch_2\">\r\n",
       "    <path d=\"M 45.478125 143.1 \r\n",
       "L 240.778125 143.1 \r\n",
       "L 240.778125 7.2 \r\n",
       "L 45.478125 7.2 \r\n",
       "z\r\n",
       "\" style=\"fill:#ffffff;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"matplotlib.axis_1\">\r\n",
       "    <g id=\"xtick_1\">\r\n",
       "     <g id=\"line2d_1\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 82.959943 143.1 \r\n",
       "L 82.959943 7.2 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_2\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 0 0 \r\n",
       "L 0 3.5 \r\n",
       "\" id=\"me65b86d805\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n",
       "      </defs>\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"82.959943\" xlink:href=\"#me65b86d805\" y=\"143.1\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_1\">\r\n",
       "      <!-- 20 -->\r\n",
       "      <g transform=\"translate(76.597443 157.698438)scale(0.1 -0.1)\">\r\n",
       "       <defs>\r\n",
       "        <path d=\"M 19.1875 8.296875 \r\n",
       "L 53.609375 8.296875 \r\n",
       "L 53.609375 0 \r\n",
       "L 7.328125 0 \r\n",
       "L 7.328125 8.296875 \r\n",
       "Q 12.9375 14.109375 22.625 23.890625 \r\n",
       "Q 32.328125 33.6875 34.8125 36.53125 \r\n",
       "Q 39.546875 41.84375 41.421875 45.53125 \r\n",
       "Q 43.3125 49.21875 43.3125 52.78125 \r\n",
       "Q 43.3125 58.59375 39.234375 62.25 \r\n",
       "Q 35.15625 65.921875 28.609375 65.921875 \r\n",
       "Q 23.96875 65.921875 18.8125 64.3125 \r\n",
       "Q 13.671875 62.703125 7.8125 59.421875 \r\n",
       "L 7.8125 69.390625 \r\n",
       "Q 13.765625 71.78125 18.9375 73 \r\n",
       "Q 24.125 74.21875 28.421875 74.21875 \r\n",
       "Q 39.75 74.21875 46.484375 68.546875 \r\n",
       "Q 53.21875 62.890625 53.21875 53.421875 \r\n",
       "Q 53.21875 48.921875 51.53125 44.890625 \r\n",
       "Q 49.859375 40.875 45.40625 35.40625 \r\n",
       "Q 44.1875 33.984375 37.640625 27.21875 \r\n",
       "Q 31.109375 20.453125 19.1875 8.296875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-50\"/>\r\n",
       "        <path d=\"M 31.78125 66.40625 \r\n",
       "Q 24.171875 66.40625 20.328125 58.90625 \r\n",
       "Q 16.5 51.421875 16.5 36.375 \r\n",
       "Q 16.5 21.390625 20.328125 13.890625 \r\n",
       "Q 24.171875 6.390625 31.78125 6.390625 \r\n",
       "Q 39.453125 6.390625 43.28125 13.890625 \r\n",
       "Q 47.125 21.390625 47.125 36.375 \r\n",
       "Q 47.125 51.421875 43.28125 58.90625 \r\n",
       "Q 39.453125 66.40625 31.78125 66.40625 \r\n",
       "z\r\n",
       "M 31.78125 74.21875 \r\n",
       "Q 44.046875 74.21875 50.515625 64.515625 \r\n",
       "Q 56.984375 54.828125 56.984375 36.375 \r\n",
       "Q 56.984375 17.96875 50.515625 8.265625 \r\n",
       "Q 44.046875 -1.421875 31.78125 -1.421875 \r\n",
       "Q 19.53125 -1.421875 13.0625 8.265625 \r\n",
       "Q 6.59375 17.96875 6.59375 36.375 \r\n",
       "Q 6.59375 54.828125 13.0625 64.515625 \r\n",
       "Q 19.53125 74.21875 31.78125 74.21875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-48\"/>\r\n",
       "       </defs>\r\n",
       "       <use xlink:href=\"#DejaVuSans-50\"/>\r\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"xtick_2\">\r\n",
       "     <g id=\"line2d_3\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 122.414489 143.1 \r\n",
       "L 122.414489 7.2 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_4\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"122.414489\" xlink:href=\"#me65b86d805\" y=\"143.1\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_2\">\r\n",
       "      <!-- 40 -->\r\n",
       "      <g transform=\"translate(116.051989 157.698438)scale(0.1 -0.1)\">\r\n",
       "       <defs>\r\n",
       "        <path d=\"M 37.796875 64.3125 \r\n",
       "L 12.890625 25.390625 \r\n",
       "L 37.796875 25.390625 \r\n",
       "z\r\n",
       "M 35.203125 72.90625 \r\n",
       "L 47.609375 72.90625 \r\n",
       "L 47.609375 25.390625 \r\n",
       "L 58.015625 25.390625 \r\n",
       "L 58.015625 17.1875 \r\n",
       "L 47.609375 17.1875 \r\n",
       "L 47.609375 0 \r\n",
       "L 37.796875 0 \r\n",
       "L 37.796875 17.1875 \r\n",
       "L 4.890625 17.1875 \r\n",
       "L 4.890625 26.703125 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-52\"/>\r\n",
       "       </defs>\r\n",
       "       <use xlink:href=\"#DejaVuSans-52\"/>\r\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"xtick_3\">\r\n",
       "     <g id=\"line2d_5\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 161.869034 143.1 \r\n",
       "L 161.869034 7.2 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_6\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"161.869034\" xlink:href=\"#me65b86d805\" y=\"143.1\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_3\">\r\n",
       "      <!-- 60 -->\r\n",
       "      <g transform=\"translate(155.506534 157.698438)scale(0.1 -0.1)\">\r\n",
       "       <defs>\r\n",
       "        <path d=\"M 33.015625 40.375 \r\n",
       "Q 26.375 40.375 22.484375 35.828125 \r\n",
       "Q 18.609375 31.296875 18.609375 23.390625 \r\n",
       "Q 18.609375 15.53125 22.484375 10.953125 \r\n",
       "Q 26.375 6.390625 33.015625 6.390625 \r\n",
       "Q 39.65625 6.390625 43.53125 10.953125 \r\n",
       "Q 47.40625 15.53125 47.40625 23.390625 \r\n",
       "Q 47.40625 31.296875 43.53125 35.828125 \r\n",
       "Q 39.65625 40.375 33.015625 40.375 \r\n",
       "z\r\n",
       "M 52.59375 71.296875 \r\n",
       "L 52.59375 62.3125 \r\n",
       "Q 48.875 64.0625 45.09375 64.984375 \r\n",
       "Q 41.3125 65.921875 37.59375 65.921875 \r\n",
       "Q 27.828125 65.921875 22.671875 59.328125 \r\n",
       "Q 17.53125 52.734375 16.796875 39.40625 \r\n",
       "Q 19.671875 43.65625 24.015625 45.921875 \r\n",
       "Q 28.375 48.1875 33.59375 48.1875 \r\n",
       "Q 44.578125 48.1875 50.953125 41.515625 \r\n",
       "Q 57.328125 34.859375 57.328125 23.390625 \r\n",
       "Q 57.328125 12.15625 50.6875 5.359375 \r\n",
       "Q 44.046875 -1.421875 33.015625 -1.421875 \r\n",
       "Q 20.359375 -1.421875 13.671875 8.265625 \r\n",
       "Q 6.984375 17.96875 6.984375 36.375 \r\n",
       "Q 6.984375 53.65625 15.1875 63.9375 \r\n",
       "Q 23.390625 74.21875 37.203125 74.21875 \r\n",
       "Q 40.921875 74.21875 44.703125 73.484375 \r\n",
       "Q 48.484375 72.75 52.59375 71.296875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-54\"/>\r\n",
       "       </defs>\r\n",
       "       <use xlink:href=\"#DejaVuSans-54\"/>\r\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"xtick_4\">\r\n",
       "     <g id=\"line2d_7\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 201.32358 143.1 \r\n",
       "L 201.32358 7.2 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_8\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"201.32358\" xlink:href=\"#me65b86d805\" y=\"143.1\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_4\">\r\n",
       "      <!-- 80 -->\r\n",
       "      <g transform=\"translate(194.96108 157.698438)scale(0.1 -0.1)\">\r\n",
       "       <defs>\r\n",
       "        <path d=\"M 31.78125 34.625 \r\n",
       "Q 24.75 34.625 20.71875 30.859375 \r\n",
       "Q 16.703125 27.09375 16.703125 20.515625 \r\n",
       "Q 16.703125 13.921875 20.71875 10.15625 \r\n",
       "Q 24.75 6.390625 31.78125 6.390625 \r\n",
       "Q 38.8125 6.390625 42.859375 10.171875 \r\n",
       "Q 46.921875 13.96875 46.921875 20.515625 \r\n",
       "Q 46.921875 27.09375 42.890625 30.859375 \r\n",
       "Q 38.875 34.625 31.78125 34.625 \r\n",
       "z\r\n",
       "M 21.921875 38.8125 \r\n",
       "Q 15.578125 40.375 12.03125 44.71875 \r\n",
       "Q 8.5 49.078125 8.5 55.328125 \r\n",
       "Q 8.5 64.0625 14.71875 69.140625 \r\n",
       "Q 20.953125 74.21875 31.78125 74.21875 \r\n",
       "Q 42.671875 74.21875 48.875 69.140625 \r\n",
       "Q 55.078125 64.0625 55.078125 55.328125 \r\n",
       "Q 55.078125 49.078125 51.53125 44.71875 \r\n",
       "Q 48 40.375 41.703125 38.8125 \r\n",
       "Q 48.828125 37.15625 52.796875 32.3125 \r\n",
       "Q 56.78125 27.484375 56.78125 20.515625 \r\n",
       "Q 56.78125 9.90625 50.3125 4.234375 \r\n",
       "Q 43.84375 -1.421875 31.78125 -1.421875 \r\n",
       "Q 19.734375 -1.421875 13.25 4.234375 \r\n",
       "Q 6.78125 9.90625 6.78125 20.515625 \r\n",
       "Q 6.78125 27.484375 10.78125 32.3125 \r\n",
       "Q 14.796875 37.15625 21.921875 38.8125 \r\n",
       "z\r\n",
       "M 18.3125 54.390625 \r\n",
       "Q 18.3125 48.734375 21.84375 45.5625 \r\n",
       "Q 25.390625 42.390625 31.78125 42.390625 \r\n",
       "Q 38.140625 42.390625 41.71875 45.5625 \r\n",
       "Q 45.3125 48.734375 45.3125 54.390625 \r\n",
       "Q 45.3125 60.0625 41.71875 63.234375 \r\n",
       "Q 38.140625 66.40625 31.78125 66.40625 \r\n",
       "Q 25.390625 66.40625 21.84375 63.234375 \r\n",
       "Q 18.3125 60.0625 18.3125 54.390625 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-56\"/>\r\n",
       "       </defs>\r\n",
       "       <use xlink:href=\"#DejaVuSans-56\"/>\r\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"xtick_5\">\r\n",
       "     <g id=\"line2d_9\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 240.778125 143.1 \r\n",
       "L 240.778125 7.2 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_10\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"240.778125\" xlink:href=\"#me65b86d805\" y=\"143.1\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_5\">\r\n",
       "      <!-- 100 -->\r\n",
       "      <g transform=\"translate(231.234375 157.698438)scale(0.1 -0.1)\">\r\n",
       "       <defs>\r\n",
       "        <path d=\"M 12.40625 8.296875 \r\n",
       "L 28.515625 8.296875 \r\n",
       "L 28.515625 63.921875 \r\n",
       "L 10.984375 60.40625 \r\n",
       "L 10.984375 69.390625 \r\n",
       "L 28.421875 72.90625 \r\n",
       "L 38.28125 72.90625 \r\n",
       "L 38.28125 8.296875 \r\n",
       "L 54.390625 8.296875 \r\n",
       "L 54.390625 0 \r\n",
       "L 12.40625 0 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-49\"/>\r\n",
       "       </defs>\r\n",
       "       <use xlink:href=\"#DejaVuSans-49\"/>\r\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "       <use x=\"127.246094\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"text_6\">\r\n",
       "     <!-- epoch -->\r\n",
       "     <g transform=\"translate(127.9 171.376563)scale(0.1 -0.1)\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 56.203125 29.59375 \r\n",
       "L 56.203125 25.203125 \r\n",
       "L 14.890625 25.203125 \r\n",
       "Q 15.484375 15.921875 20.484375 11.0625 \r\n",
       "Q 25.484375 6.203125 34.421875 6.203125 \r\n",
       "Q 39.59375 6.203125 44.453125 7.46875 \r\n",
       "Q 49.3125 8.734375 54.109375 11.28125 \r\n",
       "L 54.109375 2.78125 \r\n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \r\n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \r\n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \r\n",
       "Q 5.515625 13.8125 5.515625 26.8125 \r\n",
       "Q 5.515625 40.234375 12.765625 48.109375 \r\n",
       "Q 20.015625 56 32.328125 56 \r\n",
       "Q 43.359375 56 49.78125 48.890625 \r\n",
       "Q 56.203125 41.796875 56.203125 29.59375 \r\n",
       "z\r\n",
       "M 47.21875 32.234375 \r\n",
       "Q 47.125 39.59375 43.09375 43.984375 \r\n",
       "Q 39.0625 48.390625 32.421875 48.390625 \r\n",
       "Q 24.90625 48.390625 20.390625 44.140625 \r\n",
       "Q 15.875 39.890625 15.1875 32.171875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-101\"/>\r\n",
       "       <path d=\"M 18.109375 8.203125 \r\n",
       "L 18.109375 -20.796875 \r\n",
       "L 9.078125 -20.796875 \r\n",
       "L 9.078125 54.6875 \r\n",
       "L 18.109375 54.6875 \r\n",
       "L 18.109375 46.390625 \r\n",
       "Q 20.953125 51.265625 25.265625 53.625 \r\n",
       "Q 29.59375 56 35.59375 56 \r\n",
       "Q 45.5625 56 51.78125 48.09375 \r\n",
       "Q 58.015625 40.1875 58.015625 27.296875 \r\n",
       "Q 58.015625 14.40625 51.78125 6.484375 \r\n",
       "Q 45.5625 -1.421875 35.59375 -1.421875 \r\n",
       "Q 29.59375 -1.421875 25.265625 0.953125 \r\n",
       "Q 20.953125 3.328125 18.109375 8.203125 \r\n",
       "z\r\n",
       "M 48.6875 27.296875 \r\n",
       "Q 48.6875 37.203125 44.609375 42.84375 \r\n",
       "Q 40.53125 48.484375 33.40625 48.484375 \r\n",
       "Q 26.265625 48.484375 22.1875 42.84375 \r\n",
       "Q 18.109375 37.203125 18.109375 27.296875 \r\n",
       "Q 18.109375 17.390625 22.1875 11.75 \r\n",
       "Q 26.265625 6.109375 33.40625 6.109375 \r\n",
       "Q 40.53125 6.109375 44.609375 11.75 \r\n",
       "Q 48.6875 17.390625 48.6875 27.296875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-112\"/>\r\n",
       "       <path d=\"M 30.609375 48.390625 \r\n",
       "Q 23.390625 48.390625 19.1875 42.75 \r\n",
       "Q 14.984375 37.109375 14.984375 27.296875 \r\n",
       "Q 14.984375 17.484375 19.15625 11.84375 \r\n",
       "Q 23.34375 6.203125 30.609375 6.203125 \r\n",
       "Q 37.796875 6.203125 41.984375 11.859375 \r\n",
       "Q 46.1875 17.53125 46.1875 27.296875 \r\n",
       "Q 46.1875 37.015625 41.984375 42.703125 \r\n",
       "Q 37.796875 48.390625 30.609375 48.390625 \r\n",
       "z\r\n",
       "M 30.609375 56 \r\n",
       "Q 42.328125 56 49.015625 48.375 \r\n",
       "Q 55.71875 40.765625 55.71875 27.296875 \r\n",
       "Q 55.71875 13.875 49.015625 6.21875 \r\n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \r\n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \r\n",
       "Q 5.515625 13.875 5.515625 27.296875 \r\n",
       "Q 5.515625 40.765625 12.171875 48.375 \r\n",
       "Q 18.84375 56 30.609375 56 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-111\"/>\r\n",
       "       <path d=\"M 48.78125 52.59375 \r\n",
       "L 48.78125 44.1875 \r\n",
       "Q 44.96875 46.296875 41.140625 47.34375 \r\n",
       "Q 37.3125 48.390625 33.40625 48.390625 \r\n",
       "Q 24.65625 48.390625 19.8125 42.84375 \r\n",
       "Q 14.984375 37.3125 14.984375 27.296875 \r\n",
       "Q 14.984375 17.28125 19.8125 11.734375 \r\n",
       "Q 24.65625 6.203125 33.40625 6.203125 \r\n",
       "Q 37.3125 6.203125 41.140625 7.25 \r\n",
       "Q 44.96875 8.296875 48.78125 10.40625 \r\n",
       "L 48.78125 2.09375 \r\n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \r\n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \r\n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \r\n",
       "Q 5.515625 14.109375 5.515625 27.296875 \r\n",
       "Q 5.515625 40.671875 12.859375 48.328125 \r\n",
       "Q 20.21875 56 33.015625 56 \r\n",
       "Q 37.15625 56 41.109375 55.140625 \r\n",
       "Q 45.0625 54.296875 48.78125 52.59375 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-99\"/>\r\n",
       "       <path d=\"M 54.890625 33.015625 \r\n",
       "L 54.890625 0 \r\n",
       "L 45.90625 0 \r\n",
       "L 45.90625 32.71875 \r\n",
       "Q 45.90625 40.484375 42.875 44.328125 \r\n",
       "Q 39.84375 48.1875 33.796875 48.1875 \r\n",
       "Q 26.515625 48.1875 22.3125 43.546875 \r\n",
       "Q 18.109375 38.921875 18.109375 30.90625 \r\n",
       "L 18.109375 0 \r\n",
       "L 9.078125 0 \r\n",
       "L 9.078125 75.984375 \r\n",
       "L 18.109375 75.984375 \r\n",
       "L 18.109375 46.1875 \r\n",
       "Q 21.34375 51.125 25.703125 53.5625 \r\n",
       "Q 30.078125 56 35.796875 56 \r\n",
       "Q 45.21875 56 50.046875 50.171875 \r\n",
       "Q 54.890625 44.34375 54.890625 33.015625 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-104\"/>\r\n",
       "      </defs>\r\n",
       "      <use xlink:href=\"#DejaVuSans-101\"/>\r\n",
       "      <use x=\"61.523438\" xlink:href=\"#DejaVuSans-112\"/>\r\n",
       "      <use x=\"125\" xlink:href=\"#DejaVuSans-111\"/>\r\n",
       "      <use x=\"186.181641\" xlink:href=\"#DejaVuSans-99\"/>\r\n",
       "      <use x=\"241.162109\" xlink:href=\"#DejaVuSans-104\"/>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "   </g>\r\n",
       "   <g id=\"matplotlib.axis_2\">\r\n",
       "    <g id=\"ytick_1\">\r\n",
       "     <g id=\"line2d_11\">\r\n",
       "      <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 45.478125 64.844082 \r\n",
       "L 240.778125 64.844082 \r\n",
       "\" style=\"fill:none;stroke:#b0b0b0;stroke-linecap:square;stroke-width:0.8;\"/>\r\n",
       "     </g>\r\n",
       "     <g id=\"line2d_12\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 0 0 \r\n",
       "L -3.5 0 \r\n",
       "\" id=\"m52f2d3beec\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n",
       "      </defs>\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.478125\" xlink:href=\"#m52f2d3beec\" y=\"64.844082\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "     <g id=\"text_7\">\r\n",
       "      <!-- $\\mathdefault{10^{0}}$ -->\r\n",
       "      <g transform=\"translate(20.878125 68.643301)scale(0.1 -0.1)\">\r\n",
       "       <use transform=\"translate(0 0.765625)\" xlink:href=\"#DejaVuSans-49\"/>\r\n",
       "       <use transform=\"translate(63.623047 0.765625)\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "       <use transform=\"translate(128.203125 39.046875)scale(0.7)\" xlink:href=\"#DejaVuSans-48\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_2\">\r\n",
       "     <g id=\"line2d_13\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 0 0 \r\n",
       "L -2 0 \r\n",
       "\" id=\"mc58d643c5d\" style=\"stroke:#000000;stroke-width:0.6;\"/>\r\n",
       "      </defs>\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"127.507966\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_3\">\r\n",
       "     <g id=\"line2d_14\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"111.721077\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_4\">\r\n",
       "     <g id=\"line2d_15\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"100.5201\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_5\">\r\n",
       "     <g id=\"line2d_16\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"91.831948\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_6\">\r\n",
       "     <g id=\"line2d_17\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"84.733211\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_7\">\r\n",
       "     <g id=\"line2d_18\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"78.731314\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_8\">\r\n",
       "     <g id=\"line2d_19\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"73.532234\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_9\">\r\n",
       "     <g id=\"line2d_20\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"68.946321\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_10\">\r\n",
       "     <g id=\"line2d_21\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"37.856216\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_11\">\r\n",
       "     <g id=\"line2d_22\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"22.069326\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"ytick_12\">\r\n",
       "     <g id=\"line2d_23\">\r\n",
       "      <g>\r\n",
       "       <use style=\"stroke:#000000;stroke-width:0.6;\" x=\"45.478125\" xlink:href=\"#mc58d643c5d\" y=\"10.86835\"/>\r\n",
       "      </g>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"text_8\">\r\n",
       "     <!-- rmse -->\r\n",
       "     <g transform=\"translate(14.798437 87.669531)rotate(-90)scale(0.1 -0.1)\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 41.109375 46.296875 \r\n",
       "Q 39.59375 47.171875 37.8125 47.578125 \r\n",
       "Q 36.03125 48 33.890625 48 \r\n",
       "Q 26.265625 48 22.1875 43.046875 \r\n",
       "Q 18.109375 38.09375 18.109375 28.8125 \r\n",
       "L 18.109375 0 \r\n",
       "L 9.078125 0 \r\n",
       "L 9.078125 54.6875 \r\n",
       "L 18.109375 54.6875 \r\n",
       "L 18.109375 46.1875 \r\n",
       "Q 20.953125 51.171875 25.484375 53.578125 \r\n",
       "Q 30.03125 56 36.53125 56 \r\n",
       "Q 37.453125 56 38.578125 55.875 \r\n",
       "Q 39.703125 55.765625 41.0625 55.515625 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-114\"/>\r\n",
       "       <path d=\"M 52 44.1875 \r\n",
       "Q 55.375 50.25 60.0625 53.125 \r\n",
       "Q 64.75 56 71.09375 56 \r\n",
       "Q 79.640625 56 84.28125 50.015625 \r\n",
       "Q 88.921875 44.046875 88.921875 33.015625 \r\n",
       "L 88.921875 0 \r\n",
       "L 79.890625 0 \r\n",
       "L 79.890625 32.71875 \r\n",
       "Q 79.890625 40.578125 77.09375 44.375 \r\n",
       "Q 74.3125 48.1875 68.609375 48.1875 \r\n",
       "Q 61.625 48.1875 57.5625 43.546875 \r\n",
       "Q 53.515625 38.921875 53.515625 30.90625 \r\n",
       "L 53.515625 0 \r\n",
       "L 44.484375 0 \r\n",
       "L 44.484375 32.71875 \r\n",
       "Q 44.484375 40.625 41.703125 44.40625 \r\n",
       "Q 38.921875 48.1875 33.109375 48.1875 \r\n",
       "Q 26.21875 48.1875 22.15625 43.53125 \r\n",
       "Q 18.109375 38.875 18.109375 30.90625 \r\n",
       "L 18.109375 0 \r\n",
       "L 9.078125 0 \r\n",
       "L 9.078125 54.6875 \r\n",
       "L 18.109375 54.6875 \r\n",
       "L 18.109375 46.1875 \r\n",
       "Q 21.1875 51.21875 25.484375 53.609375 \r\n",
       "Q 29.78125 56 35.6875 56 \r\n",
       "Q 41.65625 56 45.828125 52.96875 \r\n",
       "Q 50 49.953125 52 44.1875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-109\"/>\r\n",
       "       <path d=\"M 44.28125 53.078125 \r\n",
       "L 44.28125 44.578125 \r\n",
       "Q 40.484375 46.53125 36.375 47.5 \r\n",
       "Q 32.28125 48.484375 27.875 48.484375 \r\n",
       "Q 21.1875 48.484375 17.84375 46.4375 \r\n",
       "Q 14.5 44.390625 14.5 40.28125 \r\n",
       "Q 14.5 37.15625 16.890625 35.375 \r\n",
       "Q 19.28125 33.59375 26.515625 31.984375 \r\n",
       "L 29.59375 31.296875 \r\n",
       "Q 39.15625 29.25 43.1875 25.515625 \r\n",
       "Q 47.21875 21.78125 47.21875 15.09375 \r\n",
       "Q 47.21875 7.46875 41.1875 3.015625 \r\n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \r\n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \r\n",
       "Q 10.6875 0.296875 5.421875 2 \r\n",
       "L 5.421875 11.28125 \r\n",
       "Q 10.40625 8.6875 15.234375 7.390625 \r\n",
       "Q 20.0625 6.109375 24.8125 6.109375 \r\n",
       "Q 31.15625 6.109375 34.5625 8.28125 \r\n",
       "Q 37.984375 10.453125 37.984375 14.40625 \r\n",
       "Q 37.984375 18.0625 35.515625 20.015625 \r\n",
       "Q 33.0625 21.96875 24.703125 23.78125 \r\n",
       "L 21.578125 24.515625 \r\n",
       "Q 13.234375 26.265625 9.515625 29.90625 \r\n",
       "Q 5.8125 33.546875 5.8125 39.890625 \r\n",
       "Q 5.8125 47.609375 11.28125 51.796875 \r\n",
       "Q 16.75 56 26.8125 56 \r\n",
       "Q 31.78125 56 36.171875 55.265625 \r\n",
       "Q 40.578125 54.546875 44.28125 53.078125 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-115\"/>\r\n",
       "      </defs>\r\n",
       "      <use xlink:href=\"#DejaVuSans-114\"/>\r\n",
       "      <use x=\"39.363281\" xlink:href=\"#DejaVuSans-109\"/>\r\n",
       "      <use x=\"136.775391\" xlink:href=\"#DejaVuSans-115\"/>\r\n",
       "      <use x=\"188.875\" xlink:href=\"#DejaVuSans-101\"/>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "   </g>\r\n",
       "   <g id=\"line2d_24\">\r\n",
       "    <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 45.478125 13.52902 \r\n",
       "L 47.450852 21.426618 \r\n",
       "L 49.42358 26.894433 \r\n",
       "L 51.396307 31.241986 \r\n",
       "L 53.369034 34.972667 \r\n",
       "L 55.341761 38.281561 \r\n",
       "L 57.314489 41.302524 \r\n",
       "L 59.287216 44.099568 \r\n",
       "L 61.259943 46.723536 \r\n",
       "L 63.23267 49.191105 \r\n",
       "L 65.205398 51.548064 \r\n",
       "L 67.178125 53.800055 \r\n",
       "L 69.150852 55.990763 \r\n",
       "L 71.12358 58.104002 \r\n",
       "L 73.096307 60.179677 \r\n",
       "L 75.069034 62.183451 \r\n",
       "L 77.041761 64.148249 \r\n",
       "L 79.014489 66.062694 \r\n",
       "L 80.987216 67.94868 \r\n",
       "L 82.959943 69.804802 \r\n",
       "L 84.93267 71.631522 \r\n",
       "L 86.905398 73.454092 \r\n",
       "L 88.878125 75.231845 \r\n",
       "L 90.850852 76.977584 \r\n",
       "L 92.82358 78.711958 \r\n",
       "L 94.796307 80.454552 \r\n",
       "L 96.769034 82.148826 \r\n",
       "L 98.741761 83.85811 \r\n",
       "L 100.714489 85.536692 \r\n",
       "L 102.687216 87.177262 \r\n",
       "L 104.659943 88.843911 \r\n",
       "L 106.63267 90.454726 \r\n",
       "L 108.605398 92.073877 \r\n",
       "L 110.578125 93.666426 \r\n",
       "L 112.550852 95.277827 \r\n",
       "L 114.52358 96.835795 \r\n",
       "L 116.496307 98.423499 \r\n",
       "L 118.469034 99.93125 \r\n",
       "L 120.441761 101.452092 \r\n",
       "L 122.414489 102.954127 \r\n",
       "L 124.387216 104.404744 \r\n",
       "L 126.359943 105.863944 \r\n",
       "L 128.33267 107.267303 \r\n",
       "L 130.305398 108.654729 \r\n",
       "L 132.278125 110.056758 \r\n",
       "L 134.250852 111.390491 \r\n",
       "L 136.22358 112.70036 \r\n",
       "L 138.196307 113.963943 \r\n",
       "L 140.169034 115.202004 \r\n",
       "L 142.141761 116.391687 \r\n",
       "L 144.114489 117.515134 \r\n",
       "L 146.087216 118.625983 \r\n",
       "L 148.059943 119.712423 \r\n",
       "L 150.03267 120.714883 \r\n",
       "L 152.005398 121.685639 \r\n",
       "L 153.978125 122.60768 \r\n",
       "L 155.950852 123.48886 \r\n",
       "L 157.92358 124.303326 \r\n",
       "L 159.896307 125.109357 \r\n",
       "L 161.869034 125.863178 \r\n",
       "L 163.841761 126.546151 \r\n",
       "L 165.814489 127.232394 \r\n",
       "L 167.787216 127.841049 \r\n",
       "L 169.759943 128.417719 \r\n",
       "L 171.73267 128.965589 \r\n",
       "L 173.705398 129.434757 \r\n",
       "L 175.678125 129.892613 \r\n",
       "L 177.650852 130.292714 \r\n",
       "L 179.62358 130.662843 \r\n",
       "L 181.596307 131.000628 \r\n",
       "L 183.569034 131.296731 \r\n",
       "L 185.541761 131.572794 \r\n",
       "L 187.514489 131.830994 \r\n",
       "L 189.487216 132.046922 \r\n",
       "L 191.459943 132.259475 \r\n",
       "L 193.43267 132.44328 \r\n",
       "L 195.405398 132.606695 \r\n",
       "L 197.378125 132.752801 \r\n",
       "L 199.350852 132.892152 \r\n",
       "L 201.32358 133.008659 \r\n",
       "L 203.296307 133.114974 \r\n",
       "L 205.269034 133.205999 \r\n",
       "L 207.241761 133.296053 \r\n",
       "L 209.214489 133.368344 \r\n",
       "L 211.187216 133.428009 \r\n",
       "L 213.159943 133.4789 \r\n",
       "L 215.13267 133.541512 \r\n",
       "L 217.105398 133.567649 \r\n",
       "L 219.078125 133.606545 \r\n",
       "L 221.050852 133.636953 \r\n",
       "L 223.02358 133.662149 \r\n",
       "L 224.996307 133.678961 \r\n",
       "L 226.969034 133.69038 \r\n",
       "L 228.941761 133.689159 \r\n",
       "L 230.914489 133.692821 \r\n",
       "L 232.887216 133.705996 \r\n",
       "L 234.859943 133.715096 \r\n",
       "L 236.83267 133.714892 \r\n",
       "L 238.805398 133.707503 \r\n",
       "L 240.778125 133.728602 \r\n",
       "\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"line2d_25\">\r\n",
       "    <path clip-path=\"url(#p1fbc5dd65f)\" d=\"M 45.478125 13.377273 \r\n",
       "L 47.450852 21.237839 \r\n",
       "L 49.42358 26.674957 \r\n",
       "L 51.396307 31.0023 \r\n",
       "L 53.369034 34.716443 \r\n",
       "L 55.341761 38.007894 \r\n",
       "L 57.314489 41.005824 \r\n",
       "L 59.287216 43.788443 \r\n",
       "L 61.259943 46.397222 \r\n",
       "L 63.23267 48.856778 \r\n",
       "L 65.205398 51.200607 \r\n",
       "L 67.178125 53.43593 \r\n",
       "L 69.150852 55.613077 \r\n",
       "L 71.12358 57.712569 \r\n",
       "L 73.096307 59.775924 \r\n",
       "L 75.069034 61.763928 \r\n",
       "L 77.041761 63.719353 \r\n",
       "L 79.014489 65.619451 \r\n",
       "L 80.987216 67.496878 \r\n",
       "L 82.959943 69.342576 \r\n",
       "L 84.93267 71.156658 \r\n",
       "L 86.905398 72.969747 \r\n",
       "L 88.878125 74.738239 \r\n",
       "L 90.850852 76.475566 \r\n",
       "L 92.82358 78.2045 \r\n",
       "L 94.796307 79.939161 \r\n",
       "L 96.769034 81.630119 \r\n",
       "L 98.741761 83.334677 \r\n",
       "L 100.714489 85.010125 \r\n",
       "L 102.687216 86.652211 \r\n",
       "L 104.659943 88.319763 \r\n",
       "L 106.63267 89.93627 \r\n",
       "L 108.605398 91.558683 \r\n",
       "L 110.578125 93.161843 \r\n",
       "L 112.550852 94.782537 \r\n",
       "L 114.52358 96.361821 \r\n",
       "L 116.496307 97.96585 \r\n",
       "L 118.469034 99.493391 \r\n",
       "L 120.441761 101.047377 \r\n",
       "L 122.414489 102.578833 \r\n",
       "L 124.387216 104.069625 \r\n",
       "L 126.359943 105.568602 \r\n",
       "L 128.33267 107.023104 \r\n",
       "L 130.305398 108.460263 \r\n",
       "L 132.278125 109.917402 \r\n",
       "L 134.250852 111.310074 \r\n",
       "L 136.22358 112.697044 \r\n",
       "L 138.196307 114.037878 \r\n",
       "L 140.169034 115.356203 \r\n",
       "L 142.141761 116.635474 \r\n",
       "L 144.114489 117.849269 \r\n",
       "L 146.087216 119.056134 \r\n",
       "L 148.059943 120.247685 \r\n",
       "L 150.03267 121.356712 \r\n",
       "L 152.005398 122.43924 \r\n",
       "L 153.978125 123.471813 \r\n",
       "L 155.950852 124.469558 \r\n",
       "L 157.92358 125.403534 \r\n",
       "L 159.896307 126.329037 \r\n",
       "L 161.869034 127.207216 \r\n",
       "L 163.841761 128.012449 \r\n",
       "L 165.814489 128.815703 \r\n",
       "L 167.787216 129.54047 \r\n",
       "L 169.759943 130.229689 \r\n",
       "L 171.73267 130.891089 \r\n",
       "L 173.705398 131.467849 \r\n",
       "L 175.678125 132.031435 \r\n",
       "L 177.650852 132.523664 \r\n",
       "L 179.62358 132.993433 \r\n",
       "L 181.596307 133.42423 \r\n",
       "L 183.569034 133.803932 \r\n",
       "L 185.541761 134.156327 \r\n",
       "L 187.514489 134.489108 \r\n",
       "L 189.487216 134.766995 \r\n",
       "L 191.459943 135.034562 \r\n",
       "L 193.43267 135.275009 \r\n",
       "L 195.405398 135.488047 \r\n",
       "L 197.378125 135.678561 \r\n",
       "L 199.350852 135.861093 \r\n",
       "L 201.32358 136.012783 \r\n",
       "L 203.296307 136.161574 \r\n",
       "L 205.269034 136.282782 \r\n",
       "L 207.241761 136.41771 \r\n",
       "L 209.214489 136.512249 \r\n",
       "L 211.187216 136.58015 \r\n",
       "L 213.159943 136.651322 \r\n",
       "L 215.13267 136.732563 \r\n",
       "L 217.105398 136.764414 \r\n",
       "L 219.078125 136.805738 \r\n",
       "L 221.050852 136.849012 \r\n",
       "L 223.02358 136.872501 \r\n",
       "L 224.996307 136.890817 \r\n",
       "L 226.969034 136.907949 \r\n",
       "L 228.941761 136.914948 \r\n",
       "L 230.914489 136.921922 \r\n",
       "L 232.887216 136.914501 \r\n",
       "L 234.859943 136.922727 \r\n",
       "L 236.83267 136.89878 \r\n",
       "L 238.805398 136.893807 \r\n",
       "L 240.778125 136.915358 \r\n",
       "\" style=\"fill:none;stroke:#bf00bf;stroke-dasharray:5.55,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"patch_3\">\r\n",
       "    <path d=\"M 45.478125 143.1 \r\n",
       "L 45.478125 7.2 \r\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"patch_4\">\r\n",
       "    <path d=\"M 240.778125 143.1 \r\n",
       "L 240.778125 7.2 \r\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"patch_5\">\r\n",
       "    <path d=\"M 45.478125 143.1 \r\n",
       "L 240.778125 143.1 \r\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"patch_6\">\r\n",
       "    <path d=\"M 45.478125 7.2 \r\n",
       "L 240.778125 7.2 \r\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n",
       "   </g>\r\n",
       "   <g id=\"legend_1\">\r\n",
       "    <g id=\"patch_7\">\r\n",
       "     <path d=\"M 177.826562 44.55625 \r\n",
       "L 233.778125 44.55625 \r\n",
       "Q 235.778125 44.55625 235.778125 42.55625 \r\n",
       "L 235.778125 14.2 \r\n",
       "Q 235.778125 12.2 233.778125 12.2 \r\n",
       "L 177.826562 12.2 \r\n",
       "Q 175.826562 12.2 175.826562 14.2 \r\n",
       "L 175.826562 42.55625 \r\n",
       "Q 175.826562 44.55625 177.826562 44.55625 \r\n",
       "z\r\n",
       "\" style=\"fill:#ffffff;opacity:0.8;stroke:#cccccc;stroke-linejoin:miter;\"/>\r\n",
       "    </g>\r\n",
       "    <g id=\"line2d_26\">\r\n",
       "     <path d=\"M 179.826562 20.298437 \r\n",
       "L 199.826562 20.298437 \r\n",
       "\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\r\n",
       "    </g>\r\n",
       "    <g id=\"line2d_27\"/>\r\n",
       "    <g id=\"text_9\">\r\n",
       "     <!-- train -->\r\n",
       "     <g transform=\"translate(207.826562 23.798437)scale(0.1 -0.1)\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 18.3125 70.21875 \r\n",
       "L 18.3125 54.6875 \r\n",
       "L 36.8125 54.6875 \r\n",
       "L 36.8125 47.703125 \r\n",
       "L 18.3125 47.703125 \r\n",
       "L 18.3125 18.015625 \r\n",
       "Q 18.3125 11.328125 20.140625 9.421875 \r\n",
       "Q 21.96875 7.515625 27.59375 7.515625 \r\n",
       "L 36.8125 7.515625 \r\n",
       "L 36.8125 0 \r\n",
       "L 27.59375 0 \r\n",
       "Q 17.1875 0 13.234375 3.875 \r\n",
       "Q 9.28125 7.765625 9.28125 18.015625 \r\n",
       "L 9.28125 47.703125 \r\n",
       "L 2.6875 47.703125 \r\n",
       "L 2.6875 54.6875 \r\n",
       "L 9.28125 54.6875 \r\n",
       "L 9.28125 70.21875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-116\"/>\r\n",
       "       <path d=\"M 34.28125 27.484375 \r\n",
       "Q 23.390625 27.484375 19.1875 25 \r\n",
       "Q 14.984375 22.515625 14.984375 16.5 \r\n",
       "Q 14.984375 11.71875 18.140625 8.90625 \r\n",
       "Q 21.296875 6.109375 26.703125 6.109375 \r\n",
       "Q 34.1875 6.109375 38.703125 11.40625 \r\n",
       "Q 43.21875 16.703125 43.21875 25.484375 \r\n",
       "L 43.21875 27.484375 \r\n",
       "z\r\n",
       "M 52.203125 31.203125 \r\n",
       "L 52.203125 0 \r\n",
       "L 43.21875 0 \r\n",
       "L 43.21875 8.296875 \r\n",
       "Q 40.140625 3.328125 35.546875 0.953125 \r\n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \r\n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \r\n",
       "Q 6 8.015625 6 15.921875 \r\n",
       "Q 6 25.140625 12.171875 29.828125 \r\n",
       "Q 18.359375 34.515625 30.609375 34.515625 \r\n",
       "L 43.21875 34.515625 \r\n",
       "L 43.21875 35.40625 \r\n",
       "Q 43.21875 41.609375 39.140625 45 \r\n",
       "Q 35.0625 48.390625 27.6875 48.390625 \r\n",
       "Q 23 48.390625 18.546875 47.265625 \r\n",
       "Q 14.109375 46.140625 10.015625 43.890625 \r\n",
       "L 10.015625 52.203125 \r\n",
       "Q 14.9375 54.109375 19.578125 55.046875 \r\n",
       "Q 24.21875 56 28.609375 56 \r\n",
       "Q 40.484375 56 46.34375 49.84375 \r\n",
       "Q 52.203125 43.703125 52.203125 31.203125 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-97\"/>\r\n",
       "       <path d=\"M 9.421875 54.6875 \r\n",
       "L 18.40625 54.6875 \r\n",
       "L 18.40625 0 \r\n",
       "L 9.421875 0 \r\n",
       "z\r\n",
       "M 9.421875 75.984375 \r\n",
       "L 18.40625 75.984375 \r\n",
       "L 18.40625 64.59375 \r\n",
       "L 9.421875 64.59375 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-105\"/>\r\n",
       "       <path d=\"M 54.890625 33.015625 \r\n",
       "L 54.890625 0 \r\n",
       "L 45.90625 0 \r\n",
       "L 45.90625 32.71875 \r\n",
       "Q 45.90625 40.484375 42.875 44.328125 \r\n",
       "Q 39.84375 48.1875 33.796875 48.1875 \r\n",
       "Q 26.515625 48.1875 22.3125 43.546875 \r\n",
       "Q 18.109375 38.921875 18.109375 30.90625 \r\n",
       "L 18.109375 0 \r\n",
       "L 9.078125 0 \r\n",
       "L 9.078125 54.6875 \r\n",
       "L 18.109375 54.6875 \r\n",
       "L 18.109375 46.1875 \r\n",
       "Q 21.34375 51.125 25.703125 53.5625 \r\n",
       "Q 30.078125 56 35.796875 56 \r\n",
       "Q 45.21875 56 50.046875 50.171875 \r\n",
       "Q 54.890625 44.34375 54.890625 33.015625 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-110\"/>\r\n",
       "      </defs>\r\n",
       "      <use xlink:href=\"#DejaVuSans-116\"/>\r\n",
       "      <use x=\"39.208984\" xlink:href=\"#DejaVuSans-114\"/>\r\n",
       "      <use x=\"80.322266\" xlink:href=\"#DejaVuSans-97\"/>\r\n",
       "      <use x=\"141.601562\" xlink:href=\"#DejaVuSans-105\"/>\r\n",
       "      <use x=\"169.384766\" xlink:href=\"#DejaVuSans-110\"/>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "    <g id=\"line2d_28\">\r\n",
       "     <path d=\"M 179.826562 34.976562 \r\n",
       "L 199.826562 34.976562 \r\n",
       "\" style=\"fill:none;stroke:#bf00bf;stroke-dasharray:5.55,2.4;stroke-dashoffset:0;stroke-width:1.5;\"/>\r\n",
       "    </g>\r\n",
       "    <g id=\"line2d_29\"/>\r\n",
       "    <g id=\"text_10\">\r\n",
       "     <!-- valid -->\r\n",
       "     <g transform=\"translate(207.826562 38.476562)scale(0.1 -0.1)\">\r\n",
       "      <defs>\r\n",
       "       <path d=\"M 2.984375 54.6875 \r\n",
       "L 12.5 54.6875 \r\n",
       "L 29.59375 8.796875 \r\n",
       "L 46.6875 54.6875 \r\n",
       "L 56.203125 54.6875 \r\n",
       "L 35.6875 0 \r\n",
       "L 23.484375 0 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-118\"/>\r\n",
       "       <path d=\"M 9.421875 75.984375 \r\n",
       "L 18.40625 75.984375 \r\n",
       "L 18.40625 0 \r\n",
       "L 9.421875 0 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-108\"/>\r\n",
       "       <path d=\"M 45.40625 46.390625 \r\n",
       "L 45.40625 75.984375 \r\n",
       "L 54.390625 75.984375 \r\n",
       "L 54.390625 0 \r\n",
       "L 45.40625 0 \r\n",
       "L 45.40625 8.203125 \r\n",
       "Q 42.578125 3.328125 38.25 0.953125 \r\n",
       "Q 33.9375 -1.421875 27.875 -1.421875 \r\n",
       "Q 17.96875 -1.421875 11.734375 6.484375 \r\n",
       "Q 5.515625 14.40625 5.515625 27.296875 \r\n",
       "Q 5.515625 40.1875 11.734375 48.09375 \r\n",
       "Q 17.96875 56 27.875 56 \r\n",
       "Q 33.9375 56 38.25 53.625 \r\n",
       "Q 42.578125 51.265625 45.40625 46.390625 \r\n",
       "z\r\n",
       "M 14.796875 27.296875 \r\n",
       "Q 14.796875 17.390625 18.875 11.75 \r\n",
       "Q 22.953125 6.109375 30.078125 6.109375 \r\n",
       "Q 37.203125 6.109375 41.296875 11.75 \r\n",
       "Q 45.40625 17.390625 45.40625 27.296875 \r\n",
       "Q 45.40625 37.203125 41.296875 42.84375 \r\n",
       "Q 37.203125 48.484375 30.078125 48.484375 \r\n",
       "Q 22.953125 48.484375 18.875 42.84375 \r\n",
       "Q 14.796875 37.203125 14.796875 27.296875 \r\n",
       "z\r\n",
       "\" id=\"DejaVuSans-100\"/>\r\n",
       "      </defs>\r\n",
       "      <use xlink:href=\"#DejaVuSans-118\"/>\r\n",
       "      <use x=\"59.179688\" xlink:href=\"#DejaVuSans-97\"/>\r\n",
       "      <use x=\"120.458984\" xlink:href=\"#DejaVuSans-108\"/>\r\n",
       "      <use x=\"148.242188\" xlink:href=\"#DejaVuSans-105\"/>\r\n",
       "      <use x=\"176.025391\" xlink:href=\"#DejaVuSans-100\"/>\r\n",
       "     </g>\r\n",
       "    </g>\r\n",
       "   </g>\r\n",
       "  </g>\r\n",
       " </g>\r\n",
       " <defs>\r\n",
       "  <clipPath id=\"p1fbc5dd65f\">\r\n",
       "   <rect height=\"135.9\" width=\"195.3\" x=\"45.478125\" y=\"7.2\"/>\r\n",
       "  </clipPath>\r\n",
       " </defs>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<Figure size 252x180 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from d2l import torch as d2l\n",
    "\n",
    "k, num_epochs, lr, weight_decay, batch_size = 5, 100, 5, 0, 64\n",
    "\n",
    "train_l, valid_l = k_fold(k, train_features, train_labels, num_epochs, lr,\n",
    "                          weight_decay, batch_size)\n",
    "print(f'{k}-折验证: 平均训练log rmse: {float(train_l):f}, '\n",
    "      f'平均验证log rmse: {float(valid_l):f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73e08c83",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
